package com.jessechanrui.template.skeleton.infrastructure.demo.support.repository.impl;

import com.jessechanrui.template.skeleton.infrastructure.demo.dao.DemoDao;
import com.jessechanrui.template.skeleton.infrastructure.demo.po.DemoPO;
import com.jessechanrui.template.skeleton.infrastructure.demo.support.repository.DemoRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 示例应用服务
 * @author chenrui
 * @date 2024/1/30
 */
@Repository
public class DemoRepositoryImpl implements DemoRepository {

    @Autowired
    private DemoDao demoDao;

    @Override
    public DemoPO save(DemoPO demoPO) {
        demoPO = demoDao.save(demoPO);
        return demoPO;
    }

    @Override
    public DemoPO getById(int id) {
        Optional<DemoPO> poOpt = demoDao.findById(id);
        DemoPO demoPO = null;
        if(poOpt.isPresent()){
            demoPO =  poOpt.get();
        }
        return demoPO;
    }

    @Override
    public List<DemoPO> getAll() {
        return demoDao.findAll();
    }
}
